﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Windows.Forms;

namespace AimGameEngine.NodeEditorObject
{
    partial class PropretyButtonController : Form
    {
        NodeButtonController nodebuttoncontroller;
        public PropretyButtonController(NodeButtonController nodebuttoncontroller)
        {
            InitializeComponent();
            this.nodebuttoncontroller = nodebuttoncontroller;

            Microsoft.Xna.Framework.Input.Buttons getbutton = Microsoft.Xna.Framework.Input.Buttons.Back;
            foreach (string str in Enum.GetNames(getbutton.GetType()))
                this.comboBoxButton.Items.Add(str);

            this.comboBoxButton.SelectedItem = nodebuttoncontroller.mybuttons.ToString();

            this.comboBoxMode.SelectedItem = nodebuttoncontroller.InputMode.ToString();
        }

        private void okButton_Click(object sender, EventArgs e)
        {
            Microsoft.Xna.Framework.Input.Buttons getbutton = Microsoft.Xna.Framework.Input.Buttons.Back;
            foreach (int i in Enum.GetValues(getbutton.GetType()))
            {
                string str = Enum.GetName(getbutton.GetType(), i);
                if (str == (String)comboBoxButton.SelectedItem)
                {
                    nodebuttoncontroller.mybuttons = (Microsoft.Xna.Framework.Input.Buttons)Enum.ToObject(getbutton.GetType(), i);
                    break;
                }
            }

            String tempString = (String)this.comboBoxMode.SelectedItem;
            if (tempString == AimGameLibrary.NodeInputMode.Pressed_Release.ToString())
            {
                if (this.nodebuttoncontroller.InputMode.ToString() != tempString)
                {
                    this.nodebuttoncontroller.DictionaryObjectUpdatePressed.Clear();
                    this.nodebuttoncontroller.DictionaryObjectUpdateRelease.Clear();
                    foreach (String buttonIsdownToPressed in nodebuttoncontroller.DictionaryObjectUpdateIsdown.Keys)
                        this.nodebuttoncontroller.DictionaryObjectUpdatePressed.Add(buttonIsdownToPressed, this.nodebuttoncontroller.DictionaryObjectUpdateIsdown[buttonIsdownToPressed]);
                    foreach (String buttonIsupToRelease in nodebuttoncontroller.DictionaryObjectUpdateIsup.Keys)
                        this.nodebuttoncontroller.DictionaryObjectUpdateRelease.Add(buttonIsupToRelease, this.nodebuttoncontroller.DictionaryObjectUpdateIsup[buttonIsupToRelease]);
                }
                this.nodebuttoncontroller.InputMode = AimGameLibrary.NodeInputMode.Pressed_Release;
            }
            else if (tempString == AimGameLibrary.NodeInputMode.Isdown_Isup.ToString())
            {
                if (this.nodebuttoncontroller.InputMode.ToString() != tempString)
                {
                    this.nodebuttoncontroller.DictionaryObjectUpdateIsdown.Clear();
                    this.nodebuttoncontroller.DictionaryObjectUpdateIsup.Clear();
                    foreach (String buttonPressedToIsdown in nodebuttoncontroller.DictionaryObjectUpdatePressed.Keys)
                        this.nodebuttoncontroller.DictionaryObjectUpdateIsdown.Add(buttonPressedToIsdown, this.nodebuttoncontroller.DictionaryObjectUpdatePressed[buttonPressedToIsdown]);
                    foreach (String buttonReleaseToIsup in nodebuttoncontroller.DictionaryObjectUpdateRelease.Keys)
                        this.nodebuttoncontroller.DictionaryObjectUpdateIsup.Add(buttonReleaseToIsup, this.nodebuttoncontroller.DictionaryObjectUpdateRelease[buttonReleaseToIsup]);
                }
                this.nodebuttoncontroller.InputMode = AimGameLibrary.NodeInputMode.Isdown_Isup;
            }
        }

    }
}
